package managedbean.SCM.ShippingOrder;

import entity.SCM.PackingOrder;
import entity.SCM.PickingOrder;
import java.io.IOException;
import javax.faces.event.ActionEvent;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import session.stateless.SCM.DeliveryOrderBeanLocal;

@ManagedBean(name="addShippingOrderManagerBean")
@ViewScoped

public class AddShippingOrderManagerBean implements Serializable {
    
    public AddShippingOrderManagerBean () {
    }
    
    @EJB
    private DeliveryOrderBeanLocal deliveryOrderBeanLocal;
    
    private PackingOrder selectedPackingOrder;
    private String statusMessage;
    
    public void initView(PhaseEvent event)
    {        
        if (selectedPackingOrder == null)  
        {
            selectedPackingOrder = (PackingOrder) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("selectedPackingOrder");                          
        }
    }

    public String getStatusMessage() {
        return statusMessage;
    }

    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }

    public void saveNewShippingOrder(ActionEvent event)throws IOException
   {
        Long shippingOrderId= deliveryOrderBeanLocal.createShippingOrder(selectedPackingOrder.getId());
        statusMessage = "New Shipping Order with ID "+shippingOrderId+" Saved Successfully";
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Add New Shipping Order Result: " + statusMessage, ""));
            
    }

    public PackingOrder getSelectedPackingOrder() {
        return selectedPackingOrder;
    }

    public void setSelectedPackingOrder(PackingOrder selectedPackingOrder) {
        this.selectedPackingOrder = selectedPackingOrder;
    }

    

}
